home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / TOOLS / NSCHART.ZIP / QUICKSOR.NS < prev    next >
Encoding:
Text File  |  1987-06-05  |  941 b   |  26 lines

  1. title "QUICKSORT (x,lo,hi)"
  2. "**********************************************
  3. * Purpose:                                   *
  4. *    Sorts the elements of array x that      *
  5. *    are between the lo and hi indices       *
  6. * Input:                                     *
  7. *    x    an array (sorted or unsorted)      *
  8. *    lo   low index                          *
  9. *    hi   high index                         *
  10. * Output:                                    *
  11. *    x    sorted in ascending order          *
  12. **********************************************"
  13. if "if lo < hi" then "then" :
  14.   "pivot_value := x[lo]"
  15.   "pivot_index := lo"
  16.   for "for i := (lo+1) to hi" do
  17.     if "if╩x[i]╩<╩pivot_value" then "then" :
  18.       "increment pivot_index"
  19.       "swap x[i] and x[pivot_index]"
  20.     endif
  21.   endfor
  22.   "swap x[pivot_index] and x[lo]"
  23.   call "call quicksort(x,lo,pivot_index-1)"
  24.   call "call quicksort(x,pivot_index+1,hi)"
  25. endif
  26.